package com.psp.bu.persist.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.northend.api.go.util.StringUtil;
import com.psp.bu.model.UserBean;
import com.psp.bu.model.UserLoginLogBean;
import com.psp.bu.model.UserUpdateLogBean;
import com.psp.bu.persist.dao.UserDao;

@Repository
public class UserImpl extends BaseImpl implements UserDao {
	final String NAME_SPACE = NAME_SPACE_HEADER + ".UserMapper";

	@Override
	public int insert(UserBean userBean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", userBean);
	}

	@Override
	public UserBean selectOneByPhone(String phone) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByPhone", phone);
	}

	@Override
	public int updateLoginTime(String buid) {
		return sqlSessionTemplate.update(NAME_SPACE + ".updateLoginTime", buid);
	}

	@Override
	public UserBean selectOne(String uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByUid", uid);
	}

	@Override
	public int updatePwd(UserBean user) {
		Map<String, Object> params = new HashMap<>();
		params.put("uid", user.getBuid());
		params.put("password", user.getPassword());
		return sqlSessionTemplate.update(NAME_SPACE + ".updatePwd", params);
	}

	@Override
	public int updateUser(UserBean user) {
		Map<String, Object> params = new HashMap<>();
		params.put("buid", user.getBuid());
		params.put("nickName", user.getNickName());
		params.put("headIcon", user.getHeadIcon());
		params.put("phone", user.getPhone());
		params.put("email", user.getEmail());
		params.put("idNo", user.getIdNo());
		params.put("gender", user.getGender());
		return sqlSessionTemplate.update(NAME_SPACE + ".updateUser", user);
	}

	@Override
	public int insertLoginLog(UserLoginLogBean loginLog) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insertLoginLog", loginLog);
	}

	@Override
	public int insertUpdateLog(UserUpdateLogBean updateLog) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insertUpdateLog", updateLog);
	}

}
